package sjtu.ist.warehouse4ws.service;

import java.util.List;

import sjtu.ist.warehouse4ws.dao.ResourceDao;
import sjtu.ist.warehouse4ws.dao.cust.CustResourceDao;
import sjtu.ist.warehouse4ws.model.CustResource;
import sjtu.ist.warehouse4ws.model.Resource;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;

public class ResourceServiceImpl implements ResourceService{
	private ResourceDao resourceDao;
	private CustResourceDao custResourceDao;

	public void setResourceDao(ResourceDao resourceDao) {
		this.resourceDao = resourceDao;
	}


	public void setCustResourceDao(CustResourceDao custResourceDao) {
		this.custResourceDao = custResourceDao;
	}


	@Override
	public String addResource(Resource resource,int companyId) {
		String result;
		if(companyId==Constants.ADMIN_COMPANY_ID){
			result=this.resourceDao.save(resource);
		}else{
			CustResource cr=new CustResource();
			PropertyHelper.copyProperties(resource, cr);
			result=custResourceDao.save(cr);
		}
		return result;
	}


	@Override
	public List<Resource> getResourceById(String id) {
		// TODO Auto-generated method stub
		return (List<Resource>)resourceDao.findResourceById(id);
	}


	@Override
	public List<Resource> getResourceByGroupId(String groupId) {
		// TODO Auto-generated method stub
		return resourceDao.findResourceByGroupId(groupId);
	}

}
